package com.example.iitematicviewer.util.uploadFile;

import com.example.iitematicviewer.constant.ExceptionConstant;
import com.example.iitematicviewer.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import java.io.IOException;

/**
 * 上传文件
 */
@RequestMapping("/upload")
@RestController
public class UploadFileController {

    @Autowired
    private UploadFileService service;

    @Autowired
    private UploadFileJudgingEmptinessService judgingEmptinessService;

    @RequestMapping("/uploadFile")
    public ResultVO uploadFile(HttpServletRequest request){
        ResultVO resultVO = new ResultVO();
        try {
            judgingEmptinessService.judgingEmptiness(request,resultVO);
            resultVO = service.uploadFile(request,resultVO);
        }
        catch (Exception e){
            resultVO.setCode(ExceptionConstant.five);
            resultVO.setMessage(ExceptionConstant.badUpload + e.getMessage());
        }
        return resultVO;
    }

}
